package com.qk.management.controller;


import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActController {


    @Autowired
    private ActService actService;




    @DeleteMapping("/{id}")
    public Result deleteAct(@PathVariable("id") Integer id) {
        log.info("删除活动id:{}",id);
        actService.deleteAct(id);
        return Result.success();
    }
    @PutMapping
    public Result updateAct(@RequestBody Activity  act) {
        log.info("修改活动:{}",act);
        actService.updateAct(act);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getActById(@PathVariable Integer id) {
        log.info("查询活动id:{}",id);
        Activity act = actService.getActById(id);
        return Result.success(act);
    }

    @PostMapping
    public Result addAct(@RequestBody Activity  act) {
        log.info("新增活动: {}", act);
        actService.addAct(act);
        return Result.success();
    }

    @GetMapping
    public Result getActs(ActivityDTO actDTO) {
        PageResult<Activity> actPage = actService.getActs(actDTO);
        return Result.success(actPage);
    }
}
